home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / NET / DST.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  4KB  |  183 lines

  1. /*
  2.  * net/dst.h    Protocol independent destination cache definitions.
  3.  *
  4.  * Authors:    Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  5.  *
  6.  */
  7.  
  8. #ifndef _NET_DST_H
  9. #define _NET_DST_H
  10.  
  11. #include <linux/config.h>
  12. #include <net/neighbour.h>
  13.  
  14. /*
  15.  * 0 - no debugging messages
  16.  * 1 - rare events and bugs (default)
  17.  * 2 - trace mode.
  18.  */
  19. #ifdef  NO_ANK_FIX
  20. #define RT_CACHE_DEBUG        0
  21. #else
  22. #define RT_CACHE_DEBUG        1
  23. #endif
  24.  
  25. #define DST_GC_MIN    (1*HZ)
  26. #define DST_GC_INC    (5*HZ)
  27. #define DST_GC_MAX    (120*HZ)
  28.  
  29. struct sk_buff;
  30.  
  31. struct dst_entry
  32. {
  33.     struct dst_entry        *next;
  34.     atomic_t        refcnt;        /* tree/hash references    */
  35.     atomic_t        use;        /* client references    */
  36.     struct device            *dev;
  37.     int            obsolete;
  38.     unsigned long        lastuse;
  39.     unsigned long        expires;
  40.     unsigned        mxlock;
  41.     unsigned        pmtu;
  42.     unsigned        window;
  43.     unsigned        rtt;
  44.     unsigned long        rate_last;    /* rate limiting for ICMP */
  45.     unsigned long        rate_tokens;
  46.  
  47.     int            error;
  48.  
  49.     struct neighbour    *neighbour;
  50.     struct hh_cache        *hh;
  51.  
  52.     int            (*input)(struct sk_buff*);
  53.     int            (*output)(struct sk_buff*);
  54.  
  55. #ifdef CONFIG_NET_CLS_ROUTE
  56.     __u32            tclassid;
  57. #endif
  58.  
  59.     struct  dst_ops            *ops;
  60.         
  61.     char            info[0];
  62. };
  63.  
  64.  
  65. struct dst_ops
  66. {
  67.     unsigned short        family;
  68.     unsigned short        protocol;
  69.     unsigned        gc_thresh;
  70.  
  71.     int            (*gc)(void);
  72.     struct dst_entry *    (*check)(struct dst_entry *, __u32 cookie);
  73.     struct dst_entry *    (*reroute)(struct dst_entry *,
  74.                        struct sk_buff *);
  75.     void            (*destroy)(struct dst_entry *);
  76.     struct dst_entry *    (*negative_advice)(struct dst_entry *);
  77.     void            (*link_failure)(struct sk_buff *);
  78.  
  79.     atomic_t        entries;
  80. };
  81.  
  82. #ifdef __KERNEL__
  83.  
  84. extern struct dst_entry * dst_garbage_list;
  85. extern atomic_t    dst_total;
  86.  
  87. extern __inline__
  88. struct dst_entry * dst_clone(struct dst_entry * dst)
  89. {
  90.     if (dst)
  91.         atomic_inc(&dst->use);
  92.     return dst;
  93. }
  94.  
  95. extern __inline__
  96. void dst_release(struct dst_entry * dst)
  97. {
  98.     if (dst)
  99.         atomic_dec(&dst->use);
  100. }
  101.  
  102. /* The following primitive should be use if and only if
  103.    destination entry has just been removed from a location
  104.    accessed directly by hard irq.
  105.  */
  106. extern __inline__
  107. void dst_release_irqwait(struct dst_entry * dst)
  108. {
  109.     if (dst) {
  110.         synchronize_irq();
  111.         atomic_dec(&dst->use);
  112.     }
  113. }
  114.  
  115. extern __inline__
  116. struct dst_entry * dst_check(struct dst_entry ** dst_p, u32 cookie)
  117. {
  118.     struct dst_entry * dst = *dst_p;
  119.     if (dst && dst->obsolete)
  120.         dst = dst->ops->check(dst, cookie);
  121.     return (*dst_p = dst);
  122. }
  123.  
  124. extern __inline__
  125. struct dst_entry * dst_reroute(struct dst_entry ** dst_p, struct sk_buff *skb)
  126. {
  127.     struct dst_entry * dst = *dst_p;
  128.     if (dst && dst->obsolete)
  129.         dst = dst->ops->reroute(dst, skb);
  130.     return (*dst_p = dst);
  131. }
  132.  
  133.  
  134. extern void * dst_alloc(int size, struct dst_ops * ops);
  135. extern void __dst_free(struct dst_entry * dst);
  136. extern void dst_destroy(struct dst_entry * dst);
  137.  
  138. extern __inline__
  139. void dst_free(struct dst_entry * dst)
  140. {
  141.     if (dst->obsolete > 1)
  142.         return;
  143.     if (!atomic_read(&dst->use)) {
  144.         dst_destroy(dst);
  145.         return;
  146.     }
  147.     __dst_free(dst);
  148. }
  149.  
  150. extern __inline__ void dst_confirm(struct dst_entry *dst)
  151. {
  152.     if (dst)
  153.         neigh_confirm(dst->neighbour);
  154. }
  155.  
  156. extern __inline__ void dst_negative_advice(struct dst_entry **dst_p)
  157. {
  158.     struct dst_entry * dst = *dst_p;
  159.     if (dst && dst->ops->negative_advice)
  160.         *dst_p = dst->ops->negative_advice(dst);
  161. }
  162.  
  163. extern __inline__ void dst_link_failure(struct sk_buff *skb)
  164. {
  165.     struct dst_entry * dst = skb->dst;
  166.     if (dst && dst->ops && dst->ops->link_failure)
  167.         dst->ops->link_failure(skb);
  168. }
  169.  
  170. extern __inline__ void dst_set_expires(struct dst_entry *dst, int timeout)
  171. {
  172.     unsigned long expires = jiffies + timeout;
  173.  
  174.     if (expires == 0)
  175.         expires = 1;
  176.  
  177.     if (dst->expires == 0 || (long)(dst->expires - expires) > 0)
  178.         dst->expires = expires;
  179. }
  180. #endif
  181.  
  182. #endif /* _NET_DST_H */
  183.